package com.zjq.designpatterns.behaviors.status.code;/*
 * 版权信息: 北京千⾥马网信科技有限公司</br>
 * Copyright ©2008-2018. All rights reserved. 京ICP备16007318号
 */

/**
 * 组合课程视频状态
 *
 * @author jessie
 * @version 1.0
 * @date 2021/1/28
 */
public class CourseVideoContext {
    private CourseVideoState courseVideoState;
    //通过享元模式去共享同一个对象
    public static final PlayState PLAY_STATE = new PlayState();
    public static final StopState STOP_STATE = new StopState();
    public static final PauseState PAUSE_STATE = new PauseState();
    public static final SpeedState SPEED_STATE = new SpeedState();

    public CourseVideoContext() {
    }

    public CourseVideoContext(CourseVideoState courseVideoState) {
        this.courseVideoState = courseVideoState;
    }

    public void setCourseVideoState(CourseVideoState courseVideoState) {
        this.courseVideoState = courseVideoState;
        this.courseVideoState.setCourseVideoContext(this); //自己设置到上下文当中，通知到各个实现类
    }

    public CourseVideoState getCourseVideoState() {
        return courseVideoState;
    }

    public void play() {
        this.courseVideoState.play();
    }

    public void speed() {
        this.courseVideoState.speed();
    }

    public void pause() {
        this.courseVideoState.pause();
    }

    public void stop() {
        this.courseVideoState.stop();
    }
}
